#include <Def.h>
#include "OsgAdapter.h"

void setImageColor(osg::Image* image,float r,float g,float b)
{
	if(!image)
		return;

	for(int i=0;i<image->s();i++)
		for(int j = 0;j < image->t();j++)
		{
			auto color = image->getColor(i,j);
			if(color.a() > 0)
				image->setColor(osg::Vec4f(r,g,b,color.a()),i,j);
			else
				image->setColor(osg::Vec4f(1,1,1,0),i,j);
		}
}

osgEarth::GeoPoint stringToGeoPoint(const QString& string)
{
	const osgEarth::SpatialReference* geoSRS = GLOBAL_OSG_MAP_NODE->getMapSRS()->getGeographicSRS();
	double lon,lat = 0,alt = 0.0;
	QTextStream stream(string.toLocal8Bit());
	stream>>lon;
	stream.skipWhiteSpace();
	stream>>lat;
	stream.skipWhiteSpace();
	stream>>alt;

	return osgEarth::GeoPoint(geoSRS,lon,lat,alt);
}

QString geopointToString(const osgEarth::GeoPoint& point)
{
    return QString("%1 %2 %3").arg(point.x()).arg(point.y()).arg(point.z());
}

osg::Vec3f stringToOsgVec3f(const QString& string)
{
	double x = 0,y = 0,z = 0;
	QTextStream stream(string.toLocal8Bit());
	stream >> x;
	stream.skipWhiteSpace();
	stream >> y;
	stream.skipWhiteSpace();
	stream >> z;
	return osg::Vec3f(x,y,z);
}